﻿


 // const API_HEAD = `https://www.jihemu.com/bookapi/`;
  // const IMGSOURCE = `https://www.jihemu.com/bookapi/imgs/`;

   const API_HEAD = `https://jianaijia.com/pdlapi/`;
   const IMGSOURCE = `http:/jianaijia.com/pdlapi/imgs/`;

  var GetQueryString =(name)=>{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return unescape(r[2]); return 'null';
};

var decodeurl =(str)=>{
  var s = "";
  if (str.length == 0) return "";
  s = str.replace(/&amp;/g, "&");
  s = s.replace(/&lt;/g, "<");
  s = s.replace(/&gt;/g, ">");  
  s = s.replace(/&nbsp;/g, " ");
  s = s.replace(/&#39;/g, "\'"); 
  s = s.replace(/&quot;/g, "\"");
  return s;  
}


var isBase64=(str)=>
 {
 return str.indexOf('data:image')>-1; 
}

//去重
var uniq=(array)=>{
  var temp = []; //一个新的临时数组
  array.forEach(x=>{
    if(temp.indexOf(Number(x) ) == -1)  temp.push(Number(x));
    console.log('uniq',temp);

  })
  
  return temp;
}





var showAlert = (wrap,content,id,type)=>{ 
  
  wrap.append(` <div id="${id}" class="alert alert-${type}">
  <a href="#" class="close" data-dismiss="alert">&times;</a>
  <strong>提示！</strong>${content}  </div>`)
  $(`#${id}`).alert();
}



var checkPhone=(phone)=>{
  var re =/^[1][3,4,5,7,8][0-9]{9}$/;
  return re.test(phone)
}


function arrDistinctByProp(arr,prop){
  let obj = {};
  return arr.reduce(function(preValue,item){
      obj[item[prop]] ? '' : obj[item[prop]] = true && preValue.push(item);
      return preValue
  },[])
}

var swapItems = function(arr,index1,index2){
  arr[index1] = arr.splice(index2,1,arr[index1])[0]
  return arr
}


function isIPhoneX(){
  
  
   if (screen.height == 812 && screen.width == 375){
       //是iphoneX 
       console.log('是iphoneX/XS 系列');
     return true;
     }else{
          //不是iphoneX
          return false; 
         } }


//默认GET方法
var fstHttps =(url,data,succ,type)=>{
  console.log(url,'fsturl');
  
    $.ajax({
            url,
            type:type?type:'GET',
         
            data,
            success: function (res) {
              succ&&succ(res)
            },
        })
}


var Https =(url,data,succ,type,fail,isasync)=>{
  var senddata = { token:$.cookie('token'),buid:$.cookie('id')  }
if(!senddata.token) {window.location.href='./shopunknwo.html';return}
  
   for(var k in data){
     senddata[k] = data[k]
   }
  //  console.log(senddata,'senddata');
   
    $.ajax({
            url,
            type:type?type:'POST',
            data:senddata,
            async:isasync=='false'?!1:!0,
            // beforeSend:res=>{
            //   res.setRequestHeader("id",$.cookie('id') );
            // },
            success: function (res) {
              succ&&succ(JSON.parse(res))
            },
           
            complete: function (res) {
              if(res.status!=200){
                fail&&fail(JSON.parse(res.responseText))
              }
            },
        })
}

var excelHttps = (url, data, succ, type, fail, isasync) => {
  var senddata = { token: $.cookie('token') }
  if (!senddata.token) { window.location.href = './shopunknwo.html'; return }

  for (var k in data) {
    senddata[k] = data[k]
  }
  console.log(senddata, 'senddata');

  $.ajax({
    url,
    type: type ? type : 'POST',
    data: senddata,
    async: isasync == 'false' ? !1 : !0,
    // beforeSend:res=>{
    //   res.setRequestHeader("token",$.cookie('token') );
    // },
    success: function (res) {
      succ && succ(res)
    },

    complete: function (res) {
      if (res.status != 200) {
        fail && fail(JSON.parse(res.responseText))
      }
    },
  })
}

var formatDate = (date)=>{
 return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
}

var formatDatenotime = (date)=>{
  return `${date.getFullYear()}.${date.getMonth()+1}.${date.getDate()}`;
 }

 var formatDatenotime1 = (date)=>{
  return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`;
 }


var formatDate1 = (sd)=>{
  return sd.getFullYear()+"-"+("0" + (sd.getMonth() + 1)).slice(-2)+"-"+("0" + sd.getDate()).slice(-2);
 }

 var formatDate2 = (date)=>{
  return `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()>9?date.getHours():"0"+date.getHours()}:${date.getMinutes()>9?date.getMinutes():'0'+date.getMinutes()}`;
 }

// 家具


var account_getlist = (succ)=>{
  Https(`${API_HEAD}users/getaccount1`
  ,{},res=>{
    succ&&succ(res)
  })
}

var account_aoe= (data,succ)=>{
  let permission = $.cookie('permission')
  Https(`${API_HEAD}users/aoeboss`
  ,data,res=>{
    succ&&succ(res)
  })
}


// var account_aoe = (data,succ)=>{
//   let permission = $.cookie('permission')
//   Https(`${API_HEAD}users/aoe${permission==100?'dz':''}account`
//   ,data,res=>{
//     succ&&succ(res)
//   })
// }

var uploadimg = (base64str,succ)=>{
  Https( `${API_HEAD}upload/upload`,{base64str} ,res=>{
    succ&&succ(res)
  },'POST',()=>{},'false')
}


var dz_getprojectlist = (succ)=>{
  Https(`${API_HEAD}dz_project/getlist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var dz_project_aoe = (data,succ)=>{
  Https(`${API_HEAD}dz_project/aoe`
  ,data,res=>{
    succ&&succ(res)
  })
}


var dz_project_del = (id,succ)=>{
  Https(`${API_HEAD}dz_project/del`
  ,{id},res=>{
    succ&&succ(res)
  })
}


var dz_getprojectitemlist = (id,succ)=>{
  Https(`${API_HEAD}dz_project/getitemlist`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_getprojectitemlist1 = (id,succ)=>{
  Https(`${API_HEAD}dz_project/getitemlist1`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_projectitem_aoe = (data,succ)=>{ 
  Https(`${API_HEAD}dz_project/bk_aoeitem`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_projectitem_editsingle = (data,succ)=>{
  Https(`${API_HEAD}dz_project/editsingleprop`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_projectitem_addnew = (data,succ)=>{
  Https(`${API_HEAD}dz_project/addnew`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_category_aoeimg = (data,succ)=>{
  Https(`${API_HEAD}dz_category/bk_aoewithimg`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_user_setpwd = (pwd,succ)=>{
  Https(`${API_HEAD}users/bosssetpwd`
  ,{pwd},res=>{
    succ&&succ(res)
  })
}

var dz_category_setpwd = (pwd,succ)=>{
  Https(`${API_HEAD}users/bosssetpwd`
  ,{pwd},res=>{
    succ&&succ(res)
  })
}

var dz_category_checkpwd = (pwd,succ)=>{  
  Https(`${API_HEAD}dz_category/checkpwd1`
  ,{pwd},res=>{
    succ&&succ(res)
  })
}


var haspwd = (succ)=>{
  Https(`${API_HEAD}dz_category/haspwd`
  ,{},res=>{
    succ&&succ(res)
  })
}


var dz_category_editsingle = (data,succ)=>{
  Https(`${API_HEAD}dz_category/editsingleprop`  
  ,data,res=>{
    succ&&succ(res)
  })
}
 
var dz_projectitem_del = (id,succ)=>{
  Https(`${API_HEAD}dz_project/delitem`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_projectdetail_add = (data,succ)=>{ 
  Https(`${API_HEAD}dz_projectdetail/bk_add1`
  ,data,res=>{
    succ&&succ(res)
  })
}

var gysmedit = (g,succ)=>{ 
  Https(`${API_HEAD}users/gysm`
  ,{g},res=>{
    succ&&succ(res)
  })
}

var dz_projectdetail_edit = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/bk_add`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_updatetime = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/updatetime`
  ,data,res=>{
    succ&&succ(res)
  })
}


var dz_projectdetail_setdesc = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/bk_setdesc`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_projectdetail_setorder = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/setorder`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_projectdetail_editdata= (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/bk_editdata`
  ,
 // {name,rawData}
 data
  ,res=>{
    succ&&succ(res)
  })
}

var dz_projectdetail_getd = (id,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/getdetail`
  ,{id},res=>{
    succ&&succ(res)
  })
}




var dz_projectdetail_del = (id,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/del`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_getprojectdlist = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/getlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_projectd_copy= (id,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/copy`
  ,{id},res=>{
    succ&&succ(res)
  })
}



var dz_getcategorylist = (type,succ)=>{
  Https(`${API_HEAD}dz_category/getlistbytype`
  ,{type},res=>{
    succ&&succ(res)
  })
}

var dz_rlist = (data,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/getrlist`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_recover = (id,succ)=>{
  Https(`${API_HEAD}dz_projectdetail/recover`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_categetlist = (succ)=>{
  Https(`${API_HEAD}dz_category/getlist`
  ,{},res=>{
    succ&&succ(res)
  })
}

var dz_getallsubcategory = (cid,succ)=>{
  Https(`${API_HEAD}dz_category/getallsublist1`
  ,{cid},res=>{
    succ&&succ(res)
  })
}


var dz_delsubcate = (id,succ)=>{
  Https(`${API_HEAD}dz_category/delSubCategory`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_delcate = (id,succ)=>{
  Https(`${API_HEAD}dz_category/del`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dzsubcate_editprice = (data,succ)=>{
  Https(`${API_HEAD}dz_category/editprice`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dzsubcate_editunit = (data,succ)=>{
  Https(`${API_HEAD}dz_category/editunit`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_changepoolroom = (data,succ)=>{
  Https(`${API_HEAD}dz_room/changepool`
  ,data,res=>{
    succ&&succ(res)
  })
}



var getxs = (data,succ)=>{
  Https(`${API_HEAD}dz_category/bk_getxs`
  ,data,res=>{
    succ&&succ(res)
  })
}


var aoedzcate = (data,succ)=>{
  Https(`${API_HEAD}dz_category/bk_aoe`
  ,data,res=>{
    succ&&succ(res)
  })
}

var aoedzcate_sd = (data,succ)=>{
  Https(`${API_HEAD}dz_category/bk_aoexs`
  ,data,res=>{
    succ&&succ(res)
  })
}


var aoedzsubcate = (data,succ)=>{
  Https(`${API_HEAD}dz_category/aodSub`
  ,data,res=>{
    succ&&succ(res)
  })
}


// var text123 = (succ)=>{
//   fstHttps(`https://techcherry.cn/jbjapi/users/leasebizcreate_insure`
//   ,
//   {
//     insuranceEndTime:'2024-01-01 12:00:00',
//     "orderId":"230302527785101","insuredIdNo":"91440101MA5CTKNE0H","insuranceCorpIsvAccount":"RJPYGNCN",
//     in_insuredIdNo:'91440101MA5CTKNE0H',
//     "insuredName":"广州俱百家享租科技集团有限公司","insuredMobile":"17628321130","insuredAddress":"广东省广州市天河区","insuredMail":"nroycc@163.com",
//     "holderIdNo":"91440101MA5CTKNE0H","holderName":"广州俱百家享租科技集团有限公司","holderMobile":"17628321130","holderMail":"nroycc@163.com","holderAddress":"广东省广州市天河区"
//     ,}
//   ,res=>{
//     succ&&succ(res)
//   },'POST')
// }

// var text1234 = (succ)=>{
//   fstHttps(`https://techcherry.cn/jbjapi/users/queryleasebiz`
//   ,
//   {"orderid":"230302527785101",
//   'bankCode':'ICBC',
//   'bankName':'中国工商银行股份有限公司广州泰沙路支行',
//   'recBankAreaCode':'4401',
//   'accountName':'广州俱百家享租科技集团有限公司',
//   'cnaps':'102581002644',
//   'identifyNo':'91440101MA5CTKNE0H',
//   'accountNo':'3602073809100114062',

// }
//   ,res=>{
//     succ&&succ(res)
//   },'POST')
// }



// 房间

var aoedzroom = (data,succ)=>{
  Https(`${API_HEAD}dz_room/aoe`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dzroom_editname = (data,succ)=>{
  Https(`${API_HEAD}dz_room/editname`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dzroom_getlist = (succ)=>{
  Https(`${API_HEAD}dz_room/getlist`
  ,{},res=>{
    succ&&succ(res)
  })
}



var dzroom_getlistbyid = (ids,succ)=>{
  Https(`${API_HEAD}dz_room/getlistbyids`
  ,{ids},res=>{
    succ&&succ(res)
  })
}




var dz_roomupdatedata = (data,succ)=>{
  Https(`${API_HEAD}dz_room/updatedata`
  ,data,res=>{
    succ&&succ(res)
  })
}

var dz_getroombyid = (id,succ)=>{
  Https(`${API_HEAD}dz_room/getbyid`
  ,{id},res=>{
    succ&&succ(res)
  })
}

var dz_delroom = (id,succ)=>{
  Https(`${API_HEAD}dz_room/del`
  ,{id},res=>{
    succ&&succ(res)
  })
}



var backlogin = (username,password,succ)=>{
  fstHttps(`${API_HEAD}login/dzlogin`
  ,{username,password},res=>{
    succ&&succ(res)
  },'POST')
}





// 房间






var LoginAfter = (succ)=>{

  Https(`${API_HEAD}users/login/after`
  ,JSON.stringify({'data':{'returnProfile':!0}}) ,res=>{
    succ&&succ(res)
  })
}







  







